<template>
  <div class="my_center">
    <div class="header">
      <div class="logo"><img :src="myLogo"> </div>
      <div class="nickname">{{this.nickname}}</div>
      <div class="setting"><van-icon style="font-size: 28px" name="setting-o" /></div>
    </div>
    <div class="topText">
      <div class="collect" @click="goMySend('collect')">
        <div style="font-weight: bold;font-size: 20px">0</div>
        <div style="font-size: 16px">收藏</div>
      </div>
      <div class="lookHistory" @click="goMySend('history')">
        <div style="font-weight: bold;font-size: 20px">0</div>
        <div style="font-size: 16px">历史浏览</div>
      </div>
    </div>
    <div style="width:90%;margin:0 auto;border-bottom: 1px solid #cccccc;"></div>
    <div class="middleText">
      <div style="margin:5px 0 0  20px;font-size: 18px;font-weight: bold;">我的交易</div>
      <div class="my_get">
        <div class="my_send" @click="goMySend('mySend')">
           <div class="icon"><van-icon name="shop-o" /></div>
           <div class="title2">我的发布</div>
        </div>
        <div class="my_in" @click="toOrderList">
          <div class="icon"><van-icon name="shop-collect-o" /></div>
          <div class="title2">我的订单</div>
        </div>
        <div class="my_output" @click="goMySend('myOutput')">
          <div class="icon"><van-icon name="shop-o" /></div>
          <div class="title2">我卖出的</div>
        </div>
      </div>
    </div>
    <div class="editable">
      <van-cell title="编辑资料" to="/Edit" is-link />
      <van-cell title="发布商品" to="/publishGoods" is-link />
      <van-cell title="求购社区" to="/WantBuy" is-link />
      <van-cell title="爱心捐" is-link to="/ToPay" />


    </div>
    <div class="unlogin" @click="unlogin">
      退出登录
    </div>
  </div>
</template>
<script>
import router from "../router";
import { Dialog } from 'vant';
export default {
  name:'MY',
  data(){
    return{
      nickname:'',
      myLogo:''
    }
  },
  created() {
    this.nickname=localStorage.getItem('nickname')!=='null'?localStorage.getItem('nickname'):'小猪猪'
    this.myLogo=localStorage.getItem('userimage')!=='null'&&localStorage.getItem('userimage')!==undefined?this.$baseUrl+localStorage.getItem('userimage'):'https://img0.baidu.com/it/u=2573366289,3986834022&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400'
  },
  methods:{
    toOrderList(){
      this.$router.push('/OrderLists')
    },
    unlogin(){
      Dialog.confirm({
        title: '退出登录',
        message:
            '退出登录会保留聊天记录。',
      })
          .then(() => {
            localStorage.removeItem('token')
            localStorage.removeItem('user_id')
            localStorage.removeItem('username')
            localStorage.removeItem('userimage')
            localStorage.removeItem('nickname')
            router.push('/')
          })
          .catch(() => {
            // on cancel
          });
    },
    goMySend(val){
      this.$router.push({
        path: '/ReUse',
        query: {
          id:val
        }
      })
    }
  }
}
</script>
<style lang='less' scoped>
@import "../assets/style/theme";
/deep/.van-cell__title{
  font-size: 20px;
}
.my_center{
  .header{
    width: 100%;
    display: flex;
    flex-direction:row;
    justify-content:space-around;
    align-items: center;
    .setting{
      position: absolute;
      top: 10px;
      right: 10px;
    }
    .logo{
     display: flex;
      justify-content:center;
      align-items: center;
      height: 100px;
       width:150px;
      img{
        width: 80px;
        height: 80px;
        border-radius:50%;
      }
    }
    .nickname{
      flex: 1;
      height: 50px;
      line-height: 50px;
      font-weight: bold;
      font-size: 20px;
    }
  }
  .topText{
    width: 100%;
    height: 60px;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    .collect,.lookHistory{
      display: flex;
      flex-direction: column;
      align-items: center;
    }
  }
  .middleText{
    margin-top: 10px;
    .my_get{
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      margin: 15px 28px;
     .my_in,.my_output,.my_send{
        display: flex;
        flex-direction: column;
        align-items: center;
       .icon{
         width: 40px;
         height: 40px;
         font-size: 40px;
       }
      }
    }
  }
  .unlogin{
    border-radius: 10px;
    width: 50%;
    margin: 0 auto;
    background-color:@theme;
    text-align: center;
    height: 40px;
    line-height: 40px;
    color: red;
    font-size: 20px;
  }
}
</style>
